Function.prototype.myBind = function () {
  let bindTarget = this
  let bindArgs = [...arguments].slice(1)
  let bindThis = arguments[0]

  if (typeof bindTarget !== 'function') {
    throw new Error('Bind target is not a function')
  }
  function fnBind() {
    let restArgs = [...arguments]
    let allArgs = bindArgs.concat(restArgs)
    return bindFunc.apply(this instanceof fnBind ? this : bindThis, allArgs)
  }
  fnBind.prototype = Object.create(bindTarget.prototype || Function.prototype)
  return fnBind
}
